home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / ZMISC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  22KB  |  742 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 Zmodem routines used by Zsend and Zreceive               */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*  This module is based largely on a similar module in OPUS-CBCS V1.03b.   */
  43. /*  The original work is (C) Copyright 1986, Wynn Wagner III. The original  */
  44. /*  authors have graciously allowed us to use their code in this work.      */
  45. /*                                                                          */
  46. /*--------------------------------------------------------------------------*/
  47.  
  48. /* Include this file before any other includes or defines! */
  49.  
  50. #include "includes.h"
  51.  
  52. static int Rxtype;                               /* Type of header received                 */
  53.  
  54. static char hex[] = "0123456789abcdef";
  55.  
  56. /* Send a byte as two hex digits */
  57. #define Z_PUTHEX(i,c) {i=(c);SENDBYTE(hex[((i)&0xF0)>>4]);SENDBYTE(hex[(i)&0xF]);}
  58.  
  59. /*--------------------------------------------------------------------------*/
  60. /* Private routines                                                         */
  61. /*--------------------------------------------------------------------------*/
  62. int _Z_GetBinaryHeader (unsigned char *);
  63. int _Z_32GetBinaryHeader (unsigned char *);
  64. int _Z_GetHexHeader (unsigned char *);
  65. int _Z_GetHex (void);
  66. int _Z_TimedRead (void);
  67. long _Z_PullLongFromHeader (unsigned char *);
  68.  
  69. #ifdef MILQ
  70. /*
  71.  * Dst   - Where to put this.  Should use a static buffer, if
  72.  *         a destination is not provided
  73.  *
  74.  * Src   - The filename to be conditioned
  75.  *
  76.  * TblNm - Name of the file to use for the source of path
  77.  *         conditioning entries
  78.  *
  79.  * Mode  -
  80.  */
  81.  
  82. char *ZMdmFlNmCndtn( char *Dst,
  83.                      char *Src,
  84.                      char *Tbl,
  85.                      int   Mode ) {
  86.   char                 *p;
  87.   char                 *q;
  88.  
  89.   for ( p = Src, q = Dst; *p; ) {
  90.     switch ( *p ) {
  91.       case '/':
  92.       case '\\':
  93.         switch ( UsePaths ) {
  94.           case FALSE:
  95.             q = Dst;
  96.             break;
  97.           default:
  98.             *q++ = '/';
  99.             break;
  100.           }                            /* end of switch ( UsePaths ) */
  101.         break;
  102.       case ':':
  103.         q = Dst;
  104.         break;
  105.       default:
  106.         *q++ = (char) tolower (*p);
  107.         break;
  108.       }                                /* end of for ( p = Src ... ) */
  109.     p++;
  110.     }
  111.   *q++ = '\0';
  112.   return Dst;
  113.   }
  114. #endif
  115.  
  116. void z_message (char *s)
  117. {
  118.    if (fullscreen && un_attended)
  119.       {
  120.       if (s)
  121.          {
  122.          sb_move (file_hWnd, 2, 27);
  123.          FlLnModeSet( FILE_LN_2, 0 );
  124.          sb_puts( GetDlgItem( file_hWnd, FILE_LN_2 + GD_STATUS ), s );
  125.          }
  126. #ifndef MILQ
  127.       sb_puts (file_hWnd, "              ");
  128. #endif
  129.       sb_show ();
  130.       }
  131.    else
  132.       {
  133.       gotoxy (locate_x + 20, locate_y);
  134.       if (s)
  135.          {
  136.          (void) cputs (s);
  137.          }
  138.       (void) cputs ("               ");
  139.       }
  140. }
  141.  
  142. void z_log (char *s)
  143. {
  144.    word x, y;
  145.  
  146.    z_message (s);
  147.  
  148.    x = locate_x;
  149.    y = locate_y;
  150.    status_line (s);                              /* also does disk file
  151.                                                   * logging */
  152.    locate_x = x;
  153.    locate_y = y;
  154. }
  155.  
  156. void show_loc (unsigned long l, unsigned int w)
  157. {
  158.    char j[100];
  159.  
  160.    if (fullscreen && un_attended)
  161.       {
  162.  
  163.       (void) sprintf (j, "Ofs=%ld Retries=%d        ", l, w);
  164.       sb_move (file_hWnd, 2, 37);
  165.       sb_puts( GetDlgItem( file_hWnd, FILE_LN_2 + GD_SIZE ), j );
  166.       sb_show ();
  167.       }
  168.    else
  169.       {
  170.       gotoxy (locate_x + 35, locate_y);
  171.       (void) printf ("Ofs=%ld Retries=%d        ", l, w);
  172.       }
  173. }
  174.  
  175. /*--------------------------------------------------------------------------*/
  176. /* Z GET BYTE                                                               */
  177. /* Get a byte from the modem;                                               */
  178. /* return TIMEOUT if no read within timeout tenths,                         */
  179. /* return RCDO if carrier lost                                              */
  180. /*--------------------------------------------------------------------------*/
  181. int Z_GetByte (int tenths)
  182. {
  183.    long timeout;
  184.  
  185.    if (PEEKBYTE () >= 0)
  186.       return (MODEM_IN ());
  187.  
  188.    timeout = timerset (tenths * 10);
  189.  
  190.    do
  191.       {
  192.       if (PEEKBYTE () >= 0)
  193.          return MODEM_IN ();
  194.  
  195.       if (!CARRIER)
  196.          return RCDO;
  197.  
  198.       if (got_ESC ())
  199.          return -1;
  200.  
  201.       time_release ();
  202.       }
  203.    while (!timeup (timeout));
  204.  
  205.    return TIMEOUT;
  206. }
  207.  
  208. /*--------------------------------------------------------------------------*/
  209. /* Z PUT STRING                                                             */
  210. /* Send a string to the modem, processing for \336 (sleep 1 sec)            */
  211. /* and \335 (break signal, ignored)                                         */
  212. /*--------------------------------------------------------------------------*/
  213. void Z_PutString (register unsigned char *s)
  214. {
  215.    register unsigne